<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
    <?php
        session_start();
        if(isset($_SESSION['usuario'])){
            header('Location: ./Menu/menuPrincipal.php');
        }
        $message = '';
        if(isset($_SESSION['message'])){
            $message = $_SESSION['message'];
        }
        session_destroy();
    ?>
    <head>
        <link rel="icon" href="favicon.ico" type="image/x-icon" />
        <link rel="shortcut icon" href="favicon.ico" type="image/x-icon"/>
        <meta charset="UTF-8">
        <title>Login</title>
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
        <link rel="stylesheet" href="Resources/jquery-ui-1.11.2.custom/jquery-ui.css">
        <link rel="stylesheet" href="Resources/bootstrap/css/bootstrap.css">
        <link rel="stylesheet" href="Resources/bootstrap/css/bootstrap.css.map">
        <link rel="stylesheet" href="Resources/bootstrap/css/bootstrap-theme.css">
        <link rel="stylesheet" href="Resources/bootstrap/css/bootstrap-theme.css.map">
        <link rel="stylesheet" href="Resources/style/general.css">
        <script src="Resources/js/jquery-1.11.1.js"></script>
        <script type="text/javascript" src="Resources/jquery-ui-1.11.2.custom/jquery-ui.js"></script>
        <script type="text/javascript" src="Resources/bootstrap/js/bootstrap.js"></script>
        <link rel="stylesheet" href="Resources/style/general.css">
        <script src="Resources/js/sha3.js"></script>
    </head>
    <body>
        <div class="row">
             <div class="col-md-2"></div>
             <div class="col-xs-12 col-sm-12 col-md-8">
                 <div id="wrapper">
                     <br/>
                     
                     <img src="Resources/img/logoLogin.png" height="40%" width="40%" class="center"/>
                     
                     <br/><br/>
                     
                     <form class="form-horizontal" role="form" method="post" action="Controller/loginController.php">
                         <div class="form-group">
                            <div class="col-sm-4"></div>
                            <div class="col-sm-4">
                                <input type="text" class="form-control" id="User" name="User" placeholder="User"/>
                            </div>
                            <div class="col-sm-4"></div>
                         </div>
                         <div class="form-group">
                            <div class="col-sm-4"></div>
                            <div class="col-sm-4">
                                <input type="password" class="form-control" id="password" name="password" placeholder="Password">
                            </div>
                            <div class="col-sm-4"></div>
                         </div>
                         <div class="col-sm-4"></div>
                         <div class="col-sm-4">
                             <input id="submit" type="image" value="submit" src="Resources/img/btn_enter.png" alt="Enter" class="enterButton">
                         </div>
                         <div class="col-sm-4"></div>
                     </form>
                     <br/>
                 </div>
             </div>
             <div class="col-md-2"></div>
        </div>
        <input type="text" name="message" id="message" value="<?php echo $message; ?>" style="display: none;"/>
        <div class="cargando">
            <div id="mensaje">
                Please wait... <img src="Resources/img/ajax-loader.gif"/>
            </div>
        </div>
        <script type="text/javascript">
            $('.cargando' ).dialog({ dialogClass: "no-close", autoOpen: false, modal: true});
            if($('#message').val().length>0){
                $('.cargando').children('#mensaje').html($('#message').val());
                $('.cargando').dialog({buttons: { "Ok": {  text: 'Ok', class: 'btn btn-primary', click: function () {
                    $('.cargando').dialog( 'close' ); 
                }}}});
                $('.cargando').dialog( "open" );
            }
            $('#submit').click(function(event) {
                event.preventDefault();
                var hash = CryptoJS.SHA3($('#password').val());
                $('#password').val(hash.toString(CryptoJS.enc.Hex));
                $('.cargando').dialog({buttons: { }});
                $('.cargando').children('#mensaje').html('Please wait... <img src="Resources/img/ajax-loader.gif"/>');
                $('.cargando').dialog( "open" );
                $('.form-horizontal').submit();
            });
            $('input').keypress(function(event){
                if (event.keyCode === 13){
                    event.preventDefault();
                    var hash = CryptoJS.SHA3($('#password').val());
                    $('#password').val(hash.toString(CryptoJS.enc.Hex));
                    $('.cargando').dialog({buttons: { }});
                    $('.cargando').children('#mensaje').html('Please wait... <img src="Resources/img/ajax-loader.gif"/>');
                    $('.cargando').dialog( "open" );
                    $('.form-horizontal').submit();
                }
            });
            
        </script>
    </body>
</html>